## Replication File - Technocrat or Partisan Cabinet Ministers: 

library(ggplot2)
library(dplyr)
library(MASS)
library(tidyverse)
library(likert)
library(pscl)
library(stargazer)
library(interplot)
library(sjPlot)
library(ggeffects)
library(cowplot)
library(reshape2)
library(ggpubr)
library(margins)
library(marginaleffects)


load("SurveyMinisters.Rda")


## Plot

q2<-dplyr::select(sm,EXP4_perfilministro,QD15, QD16, QD17, QD18, QD19)


q2$Coordination.Legislature<-as.factor(q2$QD16)
q2$Coordination.Presidency<-as.factor(q2$QD17)
q2$Policy.Formulation<-as.factor(q2$QD18)
q2$Policy.Implementation<-as.factor(q2$QD19)

q2$Coordination.Legislature<-with(q2, factor(QD16, 
                                             levels = c('1', '2', '3', '4', '5'), labels = c("1.Strongly Disagree", "2.Disagree", "3.Neutral", "4.Agree", "5.Strongly Agree")))


q2$Coordination.Presidency<-with(q2, factor(QD17, 
                                            levels = c('1', '2', '3', '4', '5'), labels = c("1.Strongly Disagree", "2.Disagree", "3.Neutral", "4.Agree", "5.Strongly Agree")))


q2$Policy.Formulation<-with(q2, factor(QD18, 
                                       levels = c('1', '2', '3', '4', '5'), labels = c("1.Strongly Disagree", "2.Disagree", "3.Neutral", "4.Agree", "5.Strongly Agree")))


q2$Policy.Implementation<-with(q2, factor(QD19, 
                                          levels = c('1', '2', '3', '4', '5'), labels = c("1.Strongly Disagree", "2.Disagree", "3.Neutral", "4.Agree", "5.Strongly Agree")))





q2<-dplyr::select(q2, EXP4_perfilministro, Coordination.Legislature, Coordination.Presidency, Policy.Formulation, Policy.Implementation)

q21<-q2[ which(q2$EXP4_perfilministro=="Control"), ]
q22<-q2[ which(q2$EXP4_perfilministro=="Treat1_Tec"), ]
q23<-q2[ which(q2$EXP4_perfilministro=="Treat2_Pol"), ]

levels(q2$EXP4_perfilministro)

q2<-dplyr::select(q2, Coordination.Legislature, Coordination.Presidency, Policy.Formulation, Policy.Implementation)
q21<-dplyr::select(q21, Coordination.Legislature, Coordination.Presidency, Policy.Formulation, Policy.Implementation)
q22<-dplyr::select(q22, Coordination.Legislature, Coordination.Presidency, Policy.Formulation, Policy.Implementation)
q23<-dplyr::select(q23, Coordination.Legislature, Coordination.Presidency, Policy.Formulation, Policy.Implementation)


q3<-likert(q2)
q31<-likert(q21)
q32<-likert(q22)
q33<-likert(q23)


summary(q3)

title4 <- "Control Group"
title2 <- "T1 - Technocrat"
title3 <- "T2 - Partisan"
title1 <- "Overall"


p1<-plot(q3,
         type="bar",
         low.color = "grey",
         high.color = "black",
         text.color = "black",
         face="bold") + 
  theme(axis.text=element_text(size=12, face="bold"))






p1<-plot(q3,
         type="bar",
         low.color = "grey",
         high.color = "black",
         text.color = "black")+ 
  theme(axis.text=element_text(size=12))+
  labs(title = title1, y = "%")


p2<-plot(q31,
         type="bar",
         low.color = "grey",
         high.color = "black",
         text.color = "black")+ 
  theme(axis.text=element_text(size=12))+
  labs(title = title4, y = "")


p3<-plot(q32,
         type="bar",
         low.color = "grey",
         high.color = "black",
         text.color = "black")+ 
  theme(axis.text=element_text(size=12))+
  labs(title = title2, y = "")




p4<-plot(q33,
         type="bar",
         low.color = "grey",
         high.color = "black",
         text.color = "black")+
  theme(axis.text=element_text(size=12))+
  labs(title = title3, y = "")


p<-ggarrange(p2, p3, p4,p1,  ncol = 1, nrow = 4, common.legend = TRUE, legend="bottom")

annotate_figure(p, top = text_grob("Ministers Play a Central Role", 
                                   color = "black", face = "bold", size = 14,
                                   hjust = 0, vjust = 0.4, x = 0.01))


plot_grid(p2, p3, p4, p1, label_y = 1, ncol=1, tit)





## Models


sm$QA1_3 <- ifelse (sm$QA1_2 == "Appointed", 1, 0)
sm$QE1_2 <- ifelse (sm$QE1 == "1", 1, 0)



### Ordered Probit Models


sm$EXP4_perfilministro <-as.factor(sm$EXP4_perfilministro)
sm$EXP4_perfilministro <- relevel(sm$EXP4_perfilministro, ref = "Control")

order(sm$QD16)
sm$Coordination_Legislature<-as.ordered(sm$QD16)
sm$Coordination_Presidency<-as.ordered(sm$QD17)
sm$Policy_Formulation<-as.ordered(sm$QD18)
sm$Policy_Implementation<-as.ordered(sm$QD19)


options(scipen=999)

## Reduced Models

m1 <- polr(Coordination_Legislature ~ EXP4_perfilministro, data = sm, na.action=na.omit, method="logistic")
m2 <- polr(Coordination_Presidency ~ EXP4_perfilministro, data = sm, na.action=na.omit, method="logistic")
m3 <- polr(Policy_Formulation ~ EXP4_perfilministro, data = sm, na.action=na.omit, method="logistic")
m4 <- polr(Policy_Implementation ~ EXP4_perfilministro, data = sm, na.action=na.omit, method="logistic")

summary(m1)

stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html", out = "OrderedLogitRed.doc")

## Full Models

m1 <- polr(QD16 ~ EXP4_perfilministro+QA1_2+QA0a_6+QA5+QA7+QE1+QE2, data = sm, na.action=na.omit, method="logistic")
m2 <- polr(QD17 ~ EXP4_perfilministro+QA1_2+QA0a_6+QA5+QA7+QE1+QE2, data = sm, na.action=na.omit, method="logistic")
m3 <- polr(QD18 ~ EXP4_perfilministro+QA1_2+QA0a_6+QA5+QA7+QE1+QE2, data = sm, na.action=na.omit, method="logistic")
m4 <- polr(QD19 ~ EXP4_perfilministro+QA1_2+QA0a_6+QA5+QA7+QE1+QE2, data = sm, na.action=na.omit, method="logistic")

summary(m3)

stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html", out = "OrderedLogitFull.doc")


### Subset Analysis

smt<-sm[ which(sm$QA1_2=="Efective"), ]
smp<-sm[ which(sm$QA1_2=="Appointed"), ]

## Career Civil Servants

## Reduced Models

m1 <- polr(QD16 ~ EXP4_perfilministro, data = smt, na.action=na.omit, method="logistic")
m2 <- polr(QD17 ~ EXP4_perfilministro, data = smt, na.action=na.omit, method="logistic")
m3 <- polr(QD18 ~ EXP4_perfilministro, data = smt, na.action=na.omit, method="logistic")
m4 <- polr(QD19 ~ EXP4_perfilministro, data = smt, na.action=na.omit, method="logistic")

summary(m3)

stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html", out = "OrderedLogitTecRed.doc")


## Full Models

m1 <- polr(QD16 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smt, na.action=na.omit, method="logistic")
m2 <- polr(QD17 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smt, na.action=na.omit, method="logistic")
m3 <- polr(QD18 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smt, na.action=na.omit, method="logistic")
m4 <- polr(QD19 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smt, na.action=na.omit, method="logistic")

summary(m17)


stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html", out = "OrderedLogitTecFull.doc")

### Political Appointees

## Reduced Models

m1<- polr(QD16 ~ EXP4_perfilministro, data = smp, na.action=na.omit, method="logistic")
m2 <- polr(QD17 ~ EXP4_perfilministro, data = smp, na.action=na.omit, method="logistic")
m3 <- polr(QD18 ~ EXP4_perfilministro, data = smp, na.action=na.omit, method="logistic")
m4 <- polr(QD19 ~ EXP4_perfilministro, data = smp, na.action=na.omit, method="logistic")

stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html", out = "OrderedLogitPolRed.doc")

summary(m117)

## Full Models

m1<- polr(QD16 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smp, na.action=na.omit, method="logistic")
m2 <- polr(QD17 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smp, na.action=na.omit, method="logistic")
m3 <- polr(QD18 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smp, na.action=na.omit, method="logistic")
m4 <- polr(QD19 ~ EXP4_perfilministro+QA0a_6+QA5+QA7+QE1+QE2, data = smp, na.action=na.omit, method="logistic")

stargazer(m3, m4,m1, m2, title="Ordered Logit Regression Results", type="html",out = "OrderedLogitPolFull.doc")

summary(m16)


## OR and CI
ci<-confint.default(m1)
exp(cbind(OR = coef(m1), ci))

















